<template>
  <div class="container">
    <div class="main">
      <img class="top-img" src="../../assets/img/study/top-bg.png" alt="">
      <div class="nav">
        <div class="nav-box">
          <van-row type="flex" justify="space-around">
            <van-col span="6" v-for="item,index in navList" :key="index">
              <router-link :to="item.path">
                <img :src="item.imgurl" alt="">
                <div class="nav-title">{{item.name}}</div>
              </router-link>
            </van-col>
          </van-row>
        </div>
      </div>
      <div class="statistics">
        <div class="title">学习记录</div>
        <router-link to="/study-center/record/video" class="main">
          <div class="item">
            <div class="row1">{{learnStatic.ingCount||0}}课</div>
            <div class="row2">正在学习</div>
          </div>
          <div class="item">
            <div class="row1">{{learnStatic.edCount||0}}课</div>
            <div class="row2">已完成</div>
          </div>
          <div class="item">
            <div class="row1">{{learnStatic.secondCount||0}}小时</div>
            <div class="row2">累计学习</div>
          </div>
        </router-link>
      </div>
      <div class="course-wrap">
        <router-link class="course-title" to="news">
          <van-cell title="最新课程" is-link />
        </router-link>
        <div class="list">
          <div v-for="item in courseList" :key="item.id" class="item" @click="goDetail(item)">
            <img class="img" :src="item.firstImage|imgPath" alt="" srcset="">
            <div class="title">{{item.title}}</div>
            <div class="extra">{{item.countLearn||0}}人已学</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      learnStatic: {},
      courseList: [],
      navList: [
        {
          imgurl: require('@/assets/img/study/tab-icon-1.png'),
          name: '视频学习',
          path: '/study-center/course/video'
        },
        {
          imgurl: require('@/assets/img/study/tab-icon-2.png'),
          name: '文件学习',
          path: '/study-center/course/file'
        },
        // {
        //   imgurl: require('@/assets/img/study/tab-icon-3.png'),
        //   name: '考试中心',
        //   path: '/study-center/exam'
        // },
        // {
        //   imgurl: require('@/assets/img/study/tab-icon-4.png'),
        //   name: '笔记中心',
        //   path: '/study-center/note'
        // },
        {
          imgurl: require('@/assets/img/study/tab-icon-5.png'),
          name: '学习排名',
          path: '/study-center/ranking'
        }
      ]
    }
  },
  created () {
    this.$store.commit('setCurrentBar', 1)
    this.getLearnStatic()
    this.getCourseNew()
  },
  methods: {
    goDetail (item) {
      const { id, typeId } = item
      const type = typeId === 1 ? 'video' : 'file'
      this.$router.push({
        path: `/study-center/detail/${type}/${id}`
      })
    },
    getCourseNew () {
      this.$axios.get('/xbkj-dj/web/edu/course/new').then(res => {
        this.courseList = res.data.records
      })
    },
    // 学习统计
    getLearnStatic () {
      this.$axios.get('/xbkj-dj/web/edu/learn/static').then(res => {
        this.learnStatic = res.data
      })
    },
    getCourseList () {
      this.$axios.get('/xbkj-dj/web/edu/course/list').then(res => {})
    },
    getCourseDetail () {
      this.$axios
        .get('/xbkj-dj/web/edu/course/detail', {
          id: 65
        })
        .then(res => {})
    },
    getDetail () {
      this.$axios
        .get('/xbkj-dj/web/edu/course/attachement/detail', {
          id: 65
        })
        .then(res => {})
    }
  }
}
</script>

<style lang="less" scoped>
.top-img {
  display: block;
  width: 100%;
}
.course-wrap .van-cell {
  padding: 10px 0;
  font-weight: bold;
}
.course-wrap {
  padding: 0 20px;
  background-color: #fff;
  .course-title {
    display: block;
    margin-bottom: -15px;
  }
  .list {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    .item {
      flex: 0 0 45%;
      width: 45%;
      padding: 10px 0;
      .img {
        display: block;
        width: 100%;
        border-radius: 6px;
      }
      .title {
        line-height: 1.3;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        /*! autoprefixer: off*/
        -webkit-box-orient: vertical;
        /* autoprefixer: on*/
        -webkit-line-clamp: 2;
        font-size: 14px;
        margin: 5px 0;
      }
      .extra {
        font-size: 12px;
        color: #bebdbd;
      }
    }
  }
}
.statistics {
  padding: 20px;
  background-color: #fff;
  margin-top: 10px;
  border-bottom: 1px solid #eee;
  .title {
    font-size: 16px;
    font-weight: bold;
    line-height: 1;
    margin-bottom: 20px;
  }
  .main {
    display: flex;
    justify-content: space-around;
    .item {
      flex: 0 0 20%;
      width: 20%;
      text-align: center;
      background-color: #fef6f5;
      padding: 10px;
      border-radius: 6px;
      .row1 {
        font-size: 18px;
        font-weight: bold;
        color: #f0321d;
      }
      .row2 {
        font-size: 12px;
        color: #333;
      }
    }
  }
}

.nav {
  background-color: #fff;
}
.nav-box {
  position: relative;
  top: -20px;
  width: 90%;
  margin: 0 auto;
  padding: 15px 0 5px 0;
  // border: 1px solid #ddd;
  box-shadow: 0 0 3px #ddd;
  background-color: #fff;
  text-align: center;
  border-radius: 8px;
}
.nav-box img {
  width: 25px;
}
.nav-box .nav-title {
  padding-bottom: 10px;
  font-size: 12px;
}
</style>
